<!--
 * @Author: tushan
 * @Date: 2022-11-23 21:03:26
 * @LastEditors: tushan
 * @LastEditTime: 2022-12-06 20:51:36
 * @Description: 
-->
<template>
  <!-- 标签分组 -->
  <div
    class="w-full h-full hover"
    @dragenter.stop="iniconParent"
    @dragleave.stop="noiconParent"
    :class="item.id"
    @click.stop="openBox"
  >
    <div
      :class="RC == '1x1' ? 'iconGroupzzz' : 'iconGroupZZ'"
      @dragleave.stop="noicon"
      @dragenter.stop="inicon"
    ></div>
    <div class="iconGP pointer-events-none" :class="'f' + RC">
      <Transition v-for="ite in Arraysort(list).slice(0, 8)" :key="ite.id">
        <div class="item">
          <div class="itemBox hover">
            <img class="icon" :src="ite.src" />
            <div>{{ ite.name }}</div>
          </div>
        </div>
      </Transition>
    </div>
  </div>
</template>
<script setup>
import * as Sortable from "Sortable";
import emitter from "@/util/emitter";
import { useStore } from "vuex";
import $ from "jquery";
import { ref, watch, onUnmounted } from "vue";
import { Arraysort, deepMerge } from "../../util/tools";
const selects = ref(false);
const item = ref(props.data);
const store = useStore();
const props = defineProps({
  data: { type: Object, default: () => ({ size: "1x1" }) },
});
const list = ref(store.getters.findChildren(props.data.id) || []);
const RC = ref(props.data.size);
const refresh = (data) => {
  item.value = data;
  RC.value = data.size;
};

let noLeave = false;
let t = null;
let m = null;
const iniconParent = () => {
  m = setTimeout(() => {
    if (window.MoveData.canMove == false) {
      window.MoveData.canMove = true;
    }
  }, 300);
};
const noiconParent = () => {
  clearTimeout(m);
  window.MoveData.canMove = false;
};
const inicon = (event) => {
  if (window.MoveData.type == "component") {
    return;
  }
  selects.value = true;
  $(`.${item.value.id}`).parent().parent().addClass("selBoxsss");
  if (window.MoveData.type == "icon") {
    noLeave = true;
    window.MoveData.canMove = "lock";
    if (typeof t == "number") {
      clearTimeout(t);
    }
    t = setTimeout(() => {
      if (noLeave) {
        add();
      }
    }, 1000);
  }
};
const noicon = () => {
  $(`.${item.value.id}`).parent().parent().removeClass("selBoxsss");
  selects.value = false;
  window.MoveData.canMove = false;
  noLeave = false;
};
const openBox = () => {
  emitter.emit("addGroupBox", {
    type: "show",
    pid: props.data.id,
  });
};
const add = () => {
  emitter.emit("addGroupBox", {
    type: "add",
    pid: props.data.id,
  });
};
if (props.data?.id) {
  watch(props.data, (e) => {
    refresh(e);
  });
}
const res = () => {
  list.value = deepMerge({}, store.getters.findChildren(props.data.id));
};
emitter.on("RefreshLink", res);
onUnmounted(() => {
  emitter.off("RefreshLink", res);
});
</script>
<style lang="less">
@cor: rgba(172, 172, 172, 0.518);
.f2x4 {
  padding: 10px;
  width: 100%;
  height: 100%;
  background-color: rgb(255, 255, 255);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-column-gap: 15px;
  grid-template-rows: repeat(2, 1fr);
  > .item {
    > .itemBox {
      height: 75px;
      > img {
        border-radius: var(--iconRadius);
        box-shadow: 0px 0px 5px rgba(181, 181, 181, 0.793);
        width: 60px;
        height: 60px !important;
      }
      > div {
        display: none;
      }
    }
  }
}
.iconGroupZZ {
  position: absolute;
  top: 40px;
  left: 40px;
  width: calc(100% - 80px);
  height: calc(100% - 80px);
  z-index: 1;
  background: transparent;
}
.iconGroupzzz {
  position: absolute;
  top: 18px;
  left: 18px;
  width: calc(100% - 36px);
  height: calc(100% - 36px);
  z-index: 1;
  background: transparent;
}
.f2x2 {
  padding: 13px;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-column-gap: 15px;
  grid-row-gap: 15px;
  grid-template-rows: repeat(2, 1fr);

  > .item {
    > .itemBox {
      height: 60px;
      > img {
        border-radius: var(--iconRadius);
        box-shadow: 0px 0px 5px rgba(181, 181, 181, 0.793);
        width: 50px;
        height: 50px !important;
      }

      > div {
        display: none;
      }
    }
  }
}

.f1x1 {
  padding: 10px;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-column-gap: 5px;
  grid-row-gap: 5px;
  grid-template-rows: repeat(2, 1fr);
  > .item {
    > .itemBox {
      height: 20px;
      > img {
        border-radius: var(--iconRadius);
        box-shadow: 0px 0px 5px rgba(181, 181, 181, 0.793);
        width: 15px;
        height: 15px !important;
      }
      > div {
        display: none;
      }
    }
  }
}

.iconGP {
  border: 1px solid rgb(218, 218, 218);
  box-shadow: inset 0px 0px 15px rgb(182, 182, 182);
  border-radius: var(--iconRadius);
  background-color: rgb(0, 0, 0);
}

.selBoxsss {
  position: relative;
  z-index: 2;

  &::before {
    position: absolute;
    content: " ";
    z-index: -1;
    top: 0px;
    left: 0px;
    width: 100%;
    height: calc(100% - 20px);
    background-color: @cor;
    border-radius: var(--iconRadius);
    animation: scaleCss 1s infinite;
  }
  &::after {
    position: absolute;
    content: " ";
    z-index: -1;
    top: 0px;
    left: 0px;
    width: 100%;
    height: calc(100% - 20px);
    background-color: @cor;
    border-radius: var(--iconRadius);
    animation: scaleCss 1s infinite;
    animation-delay: 0.5s;
  }
}
@keyframes scaleCss {
  0% {
    transform: scale(1);
  }
  70% {
    opacity: 0.7;
    transform: scale(1.1);
  }
  100% {
    opacity: 0;
    transform: scale(1.2);
  }
}
</style>
